package cn.edu.ctbu.demo01.aop;

import cn.edu.ctbu.demo01.constant.REnum;
import cn.edu.ctbu.demo01.exception.RException;
import cn.edu.ctbu.demo01.util.RUtil;
import cn.edu.ctbu.demo01.vo.R;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ExceptionHandle {

    @ExceptionHandler(value = RException.class)
    public R handeler(Exception e) {
        if (e instanceof RException) {
            RException rException = (RException) e;
            return RUtil.error(rException.getCode(), rException.getMessage());
        }
        return RUtil.error(REnum.UNKOWN_ERR);
    }
}
